<?php

Class Node extends Core {
    
    function __construct() {
        
        parent::__construct();
        
        $this->load->model('nodelib');
    }
    
    
    public function lists() {
        
        $this->load->library('pagination');
        
        $node = $this->load->settings('uri');
        $limit = $this->load->settings('limit');
        
        $ORM = new NodeORM($node);
        $count = $ORM->count(new NodeFilter());
        $Filter = new NodeFilter();
        
        $data['pagination'] = $this->pagination->create($this->uri->modul_uri_string(), $count, $limit, $this->uri->current_position()+1);
        
        $Filter->order($node.'_id')->limit($limit, $this->pagination->offset());
        
        $data['list'] = $ORM->get($Filter)->result_array();
        $data['meta'] = $ORM->get_meta();
        $data['node'] = $node.'_';
        
        parent::render($data, $this->nodelib->view('list', $node));
    }
    
    
    public function item($id = 1) {
        
        $node = $this->load->settings('uri');
        $field = $this->load->settings('field');
        
        $ORM = new NodeORM($node);
        $Filter = new NodeFilter();
        $Filter->where($node.'_'.$field, $id)->limit(1);
        
        $data['item'] = $ORM->get($Filter)->row_array();
        $data['meta'] = $ORM->get_meta();
        $data['node'] = $node.'_';
        
        parent::render($data, $this->nodelib->view('item', $node));
    }
}